/*
ID:herohan1
LANG:C++
TASK:clocks
*/
 
#include<fstream>
#include<iostream>
#include<math.h>
using namespace std;
 
struct matrix{
	int data[3][3];
	matrix(){}
	matrix(int a[3][3]){
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++)
				data[i][j]=a[i][j];
	}
    void set(int a[3][3]){
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++)
				data[i][j]=a[i][j];
	}
 
    int read(int i,int j){
		return data[i][j];}
 
};
 
int matrixs[9][3][3]={
						{1,1,0,
						1,1,0,
						0,0,0 },
									{1,1,1,
								   0,0,0,
								   0,0,0},
					   {0,1,1,
					   0,1,1,
					   0,0,0},
								   {1,0,0,
								  1,0,0,
								  1,0,0},
					  {0,1,0,
					  1,1,1,
					  0,1,0},
								  {0,0,1,
								  0,0,1,
								  0,0,1},
				  {0,0,0,
		          1,1,0,
				  1,1,0},
							  {
							   0,0,0,
							   0,0,0,
							   1,1,1},
				   {
		           0,0,0,
				   0,1,1,
				   0,1,1}
};
 
 
class clocks{
public:
    int clock[3][3];
    matrix step;
	int valid[9];
	int Move[9];
 
	clocks(ifstream& infile){
		int data[3][3];
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++){
				infile>>clock[i][j];
				 data[i][j]=(12-clock[i][j])/3;
			}
        step.set(data);
		for(int k=0;k<9;k++)
			Move[k]=0;
	}
 
	void  update(matrix& step,int choice){
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++)
				step.data[i][j]-=(matrixs[choice])[i][j];
 
	}
 
 
    bool OK(matrix step){
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++){
				int mol=(abs(step.read(i,j) ))%4;
				if(  mol !=0)
					return false;
			}	
		return true;
	}
 
   //the variable i represent the i th clock
	bool move(int i,matrix step){   
			if(OK(step) ){
			cout<<"when is ok: "<<(i+1)<<endl;
			return true;}
 
			if(i>8)
		    	return false;
 
 
	 //each clock can rotate at most 4 times:0,1,2,3,
	  for(int j=3;j>=0;j--){
		    matrix newStep(step);
 
			for(int k=j;k>0;k--)
			   update(newStep,i);
 
             bool Found=move(i+1,newStep);
			if(Found==true){
				cout<<(i+1)<<endl;
				Move[i]=j;
				return true;}
 
	 }//for
	 return false;
	}
 
 
		void cal(){
		move(0,step);
	}
 
void output(ofstream& outfile){
	bool first=true;
	for(int i=0;i<9;i++)
		if(Move[i]>0){  			
			for(int j=0;j<Move[i];j++){
					if(first)
					first=false;
				else
					outfile<<" ";
				cout<<"i: "<<(i+1)<<endl;
				outfile<<(i+1);}
		}
	outfile<<endl;
 
}
};
 
int main(){
	clocks CLS(infile);
	CLS.cal();
	CLS.output(outfile);
	return 0;
}

